new Vue({
    el:'#app',
    data:{
        show: -1,
        goods:[
            {id:100, name:"剃须刀", price:199, num:8},
            {id:101, name:"保温杯", price:37.5, num:10},
            {id:102, name:"拖把", price:12.8, num:2},
            {id:103, name:"砧板", price:29.9, num:15},
            {id:104, name:"水桶", price:15, num:29},
            {id:105, name:"衣架", price:8, num:9},
            {id:106, name:"花露水", price:19.9, num:15},
            {id:107, name:"毛巾", price:17, num:3},
            {id:108, name:"不锈钢锅", price:88, num:1},
            {id:109, name:"海飞丝洗发水", price:36.8, num:12},
            {id:110, name:"数据线", price:10, num:2},
        ],
        isActive:true
    },
    methods:{
        getPrice(price){
            return "￥" + price.toFixed(2);
        },
        formatZero(num, n){
            if(String(num).length >= n) return num;
            return (Array(n).join(0) + num).slice(-n);
        },
        add(item){
            item.num --;
        },
        sub(item){
            item.num ++;
        },
        del(index){
            this.goods.splice(index,1);
        },
        active(index){
            this.show = index;
        }
    },
    filters:{
        //过滤器
        showPrice(price){
            return "￥" + price.toFixed(2);
        }
    },
    computed:{
        totalPrice(){
            
            return  this.goods.reduce(function(prev, item){
                var ss = prev + item.num * item.price;
                return ss;
            }, 0)
        }
    }
})